export default {
    addUserHistory({ data }) {
        const db = this.database();
        const col = db.collection('user_history');
        const req = {
            ...data,
            viewStamp: new Date().getTime(),
        }
        console.log('add历史记录', req);
        return col.add(req)
    },

    async getUserHistory() {
        const db = this.database();
        const col = db.collection('user_history');
        const res = await col.get()

        const result = {
            article: [],
            video: [],
            default: []
        }

        res.data.forEach(item => {
            const type = item.type || 'default'
            result[type].push(item)
        })

        return result
    }
}